#include "random.h"
//#include "timer.h"
#include <driver/cpu.h>

module_t random_module =
{
	.name = "random\0",
	.author = "dak\0",
	.license = "gpl\0",
	.desc = "provide an interface to get random numbers\0",
	.dep = "\0",
	.type = MOD_TYPE_SYSTEM,
	
	.init = random_init,
	.shut = random_shut,
};


uint32_t random_init()
{
	random_module.dev = (vfs_node_t *) devfs_mk_node(random_module.name, VFS_NODE_TYPE_DCHAR);
	//random_module.dev->read = random_read;
	
	return MOD_OK;	
}

uint32_t random_shut()
{
	devfs_dl_node(random_module.name);
	return MOD_OK;	
}


/*
 * Scrive e legge nel nulla
 */
uint32_t random_read(struct vfs_node_s *node, char *data, uint32_t size, uint64_t nb)
{
	int x = 0;
	for(x; x < size; x++)
		data[x] = random_get(); 
		
	return x;
}



uint8_t random_get()
{
	char r = 0;
	
	r = (uint8_t) timer_get_tick();
	
	return r;
}
